<?php

/**
 * Lev.levme.com [ 专业开发各种Discuz!插件 ]
 *
 * Copyright (c) 2013-2014 http://www.levme.com All rights reserved.
 *
 * Author: Mr.Lee <675049572@qq.com>
 *
 * Date: 2013-02-17 16:22:17 Mr.Lee $
 */


if(!defined('IN_DISCUZ')) {
	exit('Access Denied');
}

class plugin_levmap_forum extends plugin_levmap {
	
	public function post_editorctrl_left() {
		$lev_lang = self::$lang;
		$lm2  = self::$lm2;
		$html = '<a style="text-indent:0; background:none;padding:0;height:auto;" href="javascript:;" onclick="baidumap()">
				<img src="'.self::$PLSTATIC.'img/dumap.png"></a>';
		$html.= self::_loadextjs(1, 1).<<<EOF
		<input type="hidden" id="dumappoint">
<script type="text/javascript">
function baidumap() {
	var data = '<iframe width="960" scrolling="no" height="600" frameborder="0" marginheight="0" src="{$lm2}baidu.__map">'+
				'</iframe>';
	art.dialog({id:'baidumap', content:data, padding:0, ok:function(){
		var dumappoint = jQuery('#dumappoint').val();
		if (!dumappoint) {
			art.dialog.tips('{$lev_lang[error]}no map point!');
			return false;
		}
		var center = dumappoint.split('|');
		var src = 'http://api.map.baidu.com/staticimage?width=960&height=600&center='+ center[1]
				+'&markers='+ center[1] +'&zoom='+ center[0]+'&markerStyles=l,A,0xff0000';
		jQuery('#e_image').click();
		jQuery('#e_image_param_1').val(src);
		jQuery('#e_image_submit').click();
	}, cancel:true});
}
</script>
EOF;
		return $html;
	}
	
}

class plugin_levmap {

	public static $PL_G, $_G, $PLNAME, $PLSTATIC, $PLURL, $lang = array(), $table, $navtitle, $uploadurl, $remote, $talk;
	public static $lm, $lm2;

	public function __construct() {
		self::_init();
		self::$lang = self::_levlang();
	}
	
	public static function global_usernav_extra2() {
	}
	
	
	public static function _init() {

		global $_G;
		self::$_G     = $_G;
		self::$PLNAME = 'levmap';
		self::$PL_G   = self::$_G['cache']['plugin'][self::$PLNAME];//print_r($PL_G);

		self::$PLSTATIC = 'source/plugin/'.self::$PLNAME.'/statics/';
		self::$PLURL    = 'plugin.php?id='.self::$PLNAME;
		self::$uploadurl= self::$PLSTATIC.'upload/common/';
		self::$remote   = 'plugin.php?id='.self::$PLNAME.':l&fh='.FORMHASH.'&m=';
		self::$lm       = 'plugin.php?id='.self::$PLNAME.':l&fh='.FORMHASH.'&m=_m.';
		self::$lm2      = 'plugin.php?id='.self::$PLNAME.':l&fh='.FORMHASH.'&m=__m.';
	}

	public static function _levlang($string = '', $key = 0) {
		$sets  = $string ? $string : (!$key ? self::$PL_G['levlang'] : '');
		$lang  = array();
		if ($sets) {
			$array = explode("\n", $sets);
			foreach ($array as $r) {
				$thisr  = explode('=', trim($r));
				$lang[trim($thisr[0])] = trim($thisr[1]);
			}
			if (!$key) {
				$lang['extscore'] = self::$_G['setting']['extcredits'][self::$PL_G['scoretype']]['title'];
				$flang = lang('plugin/levmap');
				if (is_array($flang)) $lang = $lang + $flang;
			}
		}
		return $lang;
	}

	public static function _levdiconv($string, $in_charset = 'utf-8', $out_charset = CHARSET) {
		if(is_array($string)) {
			foreach($string as $key => $val) {
				$string[$key] = diconv($val, $in_charset, $out_charset);
			}
		} else {
			$string = diconv($string, $in_charset, $out_charset);
		}
		return $string;
	}
	
	public static function _isopen($key = 'close') {
		$isopen = unserialize(self::$PL_G['isopen']);
		if (is_array($isopen) && in_array($key, $isopen)) return TRUE;
	}
	
	public static function _ckopen($info, $ck) {
		$ckinfo = unserialize($info);
		if ($ckinfo[0] && !in_array($ck, $ckinfo)) return TRUE;
	}
	
	public static function _loadextjs($jquery = 0, $force = 0) {
		global $_G;
		$js = '';
		if ($jquery && (self::$_G['loadjquery'] !=1 || $force)) {
			$_G['loadjquery'] = 1;
			$js .= '<script language="javascript" type="text/javascript" src="'.self::$PLSTATIC.'jquery.min.js"></script>
					 <script language="javascript" type="text/javascript">var $$ = jQuery.noConflict();</script>';
		}
		if (self::$_G['loadartjs'] !=1 || $force) {
			$_G['loadartjs'] = 1;
			$js .= '<script type="text/javascript" src="'.self::$PLSTATIC.'dialog417/dialog.js?skin=default"></script>
				  	<script type="text/javascript" src="'.self::$PLSTATIC.'dialog417/plugins/iframeTools.js"></script>';
		}
		return $js;
	}
	
}








